package com.yc.supermarket.service.impl;

import com.yc.supermarket.entity.Sales;
import com.yc.supermarket.entity.Transaction;
import com.yc.supermarket.mapper.UnlineBuyMapper;
import com.yc.supermarket.service.IUnlineBuyService;
import com.yc.supermarket.util.MybatisUtil;
import org.apache.ibatis.session.SqlSession;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class UnlineServiceImpl implements IUnlineBuyService {
    private UnlineBuyMapper mapper;
    @Override
    public Double findprice(int gooodsid){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        Double result=mapper.findprice(gooodsid);
        return result;
    }

    @Override
    public int founds(){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        Transaction order=new Transaction();
        int results=mapper.founds(order);
        int result=order.getTransactionId();
        return result;
    }

    @Override
    public int foundtails(Sales orderTail){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        int result=mapper.foundtails(orderTail);
        return result;
    }

    @Override
    public Map<String,Object> finds(Sales orderTail){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        List<Sales> list=mapper.finds(orderTail);
        System.out.println("the list"+list);
        Map<String,Object> map=new HashMap<>();
        map.put("code",0);
        map.put("msg","");
        map.put("data",list);
        return map;
    }

    @Override
    public int submit(Transaction order){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        int result=mapper.submit(order);
        return result;
    }

    @Override
    public int doover(Sales sales){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        int a=mapper.overorder(sales);
        int b=mapper.overtail(sales);
        if(a!=0 && b!=0){
            return 1;
        }else {
            return 0;
        }
    }


    @Override
    public int modify(Sales sales){
        SqlSession session= MybatisUtil.getSession();
        mapper=session.getMapper(UnlineBuyMapper.class);
        int sa=mapper.modify(sales);
        return sa;
    }


}
